package top.anka1.ims;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.URI;

class MouseAdp implements MouseListener {
    JLabel label;
    Boolean flag = true;
    public MouseAdp(JLabel label) {
        this.label = label;
    }
    public void mouseClicked(MouseEvent e) {
        if (flag) {
            label.setFont(new Font("SansSerif", Font.PLAIN, 18));
            label.setText("<html>You found an Easter Egg! Here is a sentence of my favorite for you: <br>Beautiful Word, Beautiful World.</html>");
            flag = false;
        } else {
            label.setFont(new Font("SansSerif", Font.BOLD, 28));
            label.setText("About");
            flag = true;
        }
    }
    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {}
    public void mousePressed(MouseEvent e) {}
    public void mouseReleased(MouseEvent e) {}
}
class MouseAdp2 implements MouseListener {
    JLabel label;
    OSinfo osInfo = new OSinfo();
    public MouseAdp2(JLabel label) {
        this.label = label;
    }
    public void mouseClicked(MouseEvent e) {}
    public void mouseEntered(MouseEvent e) {
        if (osInfo.isWindows()) {
            label.setFont(new Font("Microsoft YaHei", Font.PLAIN, 12));
        } else if (osInfo.isLinux()) {
            label.setFont(new Font("Noto Sans SC", Font.PLAIN, 12));
        } else if (osInfo.isMacOS() | osInfo.isMacOSX()) {
            label.setFont(new Font("PingFang SC Medium", Font.PLAIN, 12));
        }
        label.setText("无刺藏锋藏深意，有刺反骨反万尘！");
    }
    public void mouseExited(MouseEvent e) {
        label.setFont(new Font("System", Font.PLAIN, 12));
        label.setText("Copyright © 2025 Anka All rights reserved.");
    }
    public void mousePressed(MouseEvent e) {}
    public void mouseReleased(MouseEvent e) {}
}
public class About_Copyright extends JFrame {
    public About_Copyright() {
        setTitle("About");
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setSize(600, 200);
        setLocationRelativeTo(null);
        setResizable(false);


        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new BorderLayout(20, 20));
        //mainPanel.setBackground(Color.WHITE);
        add(mainPanel);


        JLabel titleLabel = new JLabel("About", SwingConstants.CENTER);
        titleLabel.setFont(new Font("SansSerif", Font.BOLD, 28));
        titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
        titleLabel.setVerticalAlignment(SwingConstants.TOP);
        titleLabel.addMouseListener(new MouseAdp(titleLabel));
        mainPanel.add(titleLabel, BorderLayout.NORTH);


        JPanel centerPanel = new JPanel();
        //centerPanel.setBackground(Color.WHITE);
        centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));

        JLabel descriptionLabel = new JLabel("This GUI was built by Anka with JFrame.");
        descriptionLabel.setFont(new Font("SansSerif", Font.PLAIN, 16));
        descriptionLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        centerPanel.add(descriptionLabel);

        centerPanel.add(Box.createRigidArea(new Dimension(0, 20))); // 间距


        JPanel buttonPanel = new JPanel();
        //buttonPanel.setBackground(Color.WHITE);
        JButton repoButton = new JButton("Open Repository on gitee.com");
        JButton homepageButton = new JButton("Open Anka's Homepage");

        repoButton.addActionListener(e -> openURL("https://gitee.com/Anka-Victorique-de-Blois/end-of-semester-group-project"));
        homepageButton.addActionListener(e -> openURL("https://www.anka1.top"));

        buttonPanel.add(repoButton);
        buttonPanel.add(homepageButton);

        centerPanel.add(buttonPanel);
        mainPanel.add(centerPanel, BorderLayout.CENTER);


        JLabel copyrightLabel = new JLabel("<html>Copyright © 2025 Anka All rights reserved.<br></html>", SwingConstants.CENTER);
        copyrightLabel.setFont(new Font("System", Font.PLAIN, 12));
        copyrightLabel.addMouseListener(new MouseAdp2(copyrightLabel));
        mainPanel.add(copyrightLabel, BorderLayout.SOUTH);

        setVisible(true);
    }


    private void openURL(String url) {
        try {
            Desktop.getDesktop().browse(new URI(url));
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Failed to open URL.");
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(About_Copyright::new);
    }
}
